package org.egedede.processmanager.impl;

import java.io.*;
import org.egedede.processmanager.*;
import org.egedede.processmanager.logs.ProcessLog;

public class InputStreamReaderThread implements Runnable{

	private BufferedReader reader;
	private ProcessLog logger;
	private String level;

	public InputStreamReaderThread(InputStream isToRead, ProcessLog logger, String level){
		reader = new BufferedReader(new InputStreamReader(isToRead));
		this.logger = logger;
		this.level = level;
	}
	
	public void run(){
		String line = "";
		try {
			while((line = reader.readLine()) != null) {
				logger.log(level, line);
			}
		} catch(IOException e){
			e.printStackTrace();
		} finally {
			try{
			reader.close();
			}catch(Exception e){}
		}
	}
}